extends "../calxJS_Hide/calxJS_Hide.gd"
func _init():
	pass
func _extInit():
	._extInit()
	chaName = "小小丸"                   # 角色的名称
	attCoe.atkRan = 2                 # 攻击距离
	attCoe.maxHp = 5                  # 最大生命（每点代表112.5基础数值，取整数，下同）
	attCoe.atk = 4                    # 攻击力（每点代表8.5）
	attCoe.mgiAtk = 4                 # 魔法攻击（每点代表13.7）
	attCoe.def = 4                    # 物理防御（每点代表15）
	attCoe.mgiDef = 4                 # 魔法防御（每点代表16.6）
	atkEff = "atk_dang" 
	xb = "神秘"
	lv = 3   
	addSkillTxt("[陷阵之志]小小丸突击到双攻合计最高的单位身边，并嘲讽周围三格敌人[CD:9]")
	addCdSkill("xzzz",9)

func _castCdSkill(id):
	._castCdSkill(id)
	if id=="xzzz":
		xzzz()
		var chas = getCellChas(cell,4)
		for i in chas:
				i.addBuff(b_taunt.new(3, self))
				i.aiCha = self

class b_taunt:
	extends Buff
	var tcha
	func _init(lv = 1, tcha = null):
		life = lv
		isNegetive = true
		self.tcha = tcha
		id = "b_taunt"
	func _del():
		masCha.aiCha = null
		._del()
	func _upS():
		if tcha.isDeath:
			life = 0
		elif masCha.aiCha != tcha:
			masCha.aiCha = tcha


func xzzz():
	var chas = getAllChas(1)
	var isOK = false
	chas.sort_custom(self,"sort")
	var vs = [Vector2(1,0),Vector2(-1,0),Vector2(0,1),Vector2(0,-1)]
	for cha in chas:
		for v in vs:
			var v2 = cha.cell + v
			if matCha(v2) == null && sys.main.isMatin(v2):
				if setCell(v2) :
					var pos = sys.main.map.map_to_world(cell)
					ying(pos)
					position = pos
					aiOn = true
					aiCha = cha
					isOK = true
					break
		if isOK:break
		yield(reTimer(0.1),"timeout")  
func sort(a,b):
	if a.att.atk + a.att.mgiAtk > b.att.atk + b.att.mgiAtk:
		return true
	return false

func ying(pos):
	var l:Vector2 = pos - position
	var s = 25
	var rs = preload("res://core/ying.tscn")
	var n = l.length()/s
	for i in range(n):
		var spr = rs.instance()
		sys.main.map.add_child(spr)
		spr.texture = img.texture
		spr.position = position + s * (i+1) * l.normalized() - Vector2(img.texture.get_width()/2,img.texture.get_height())
		spr.init(255/n * i + 100)

